package com.funong.matrix.biz.system.facade.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.funong.matrix.biz.base.entity.SysFileBusinessEntity;
import com.funong.matrix.biz.base.entity.SysFileInfoEntity;
import com.funong.matrix.biz.system.domain.SysFileDomainDao;
import com.funong.matrix.biz.system.facade.SysFileFacade;
import com.funong.matrix.biz.system.pojo.dto.FileBaseInfoDTO;
import com.funong.matrix.biz.system.pojo.dto.FileBusinessRelationDTO;
import com.funong.matrix.biz.system.pojo.dto.FileDTO;
import com.funong.matrix.core.dto.Result;
import com.funong.matrix.core.enums.FileCategoryType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author : NaNa
 * @since : 2023-05-26 18:20
 **/

@Slf4j
@Service
public class SysFileFacadeImpl implements SysFileFacade {
    @Resource
    private SysFileDomainDao fileDomainDao;

    @Override
    public SysFileInfoEntity saveFileInfo(FileBaseInfoDTO fileBaseInfoDTO) {
        return fileDomainDao.saveFileInfo(fileBaseInfoDTO);
    }

    @Override
    public List<SysFileInfoEntity> getFileListByIds(List<Integer> fileIdList) {
        return fileDomainDao.getFileListByIds(fileIdList);
    }


    @Override
    public Result recordFileRelation(FileBusinessRelationDTO relationDTO) {
        return fileDomainDao.recordFileRelation(relationDTO);
    }

    /**
     * 删除文件关系信息
     *
     * @param bizId        来源ID
     *                     {@link FileCategoryType}
     * @param categoryType 业务文件类型
     */
    @Override
    public void deleteFileRelation(Integer bizId, String categoryType) {
        fileDomainDao.deleteFileRelation(bizId, categoryType);
    }

    /**
     * 废弃文件关系信息，改状态为无效
     *
     * @param bizId        来源ID
     *                     {@link FileCategoryType}
     * @param categoryType 业务文件类型
     */
    @Override
    public void dropFileRelation(Integer bizId, String categoryType, String memo) {
        fileDomainDao.dropFileRelation(bizId, categoryType, memo);
    }


    /**
     * 废弃文件关系信息，改状态
     *
     * @param bizId                来源ID
     *                             {@link FileCategoryType}
     * @param fileCategoryTypeList 业务文件类型
     * @param statusEnum           状态（驳回只更新文件状态为无效，isdeleted=0，未删除）
     */
    @Override
    public List<SysFileInfoEntity> getFileInfoByBizIdAndType(Integer bizId,
                                                             List<String> fileCategoryTypeList,
                                                             Integer statusEnum) {
        return fileDomainDao.getFileInfoByBizIdAndType(bizId, fileCategoryTypeList, statusEnum);
    }

    /**
     * 根据来源ID、附件类型，查询附件信息
     *
     * @param bizId                来源ID
     * @param fileCategoryTypeList 附件类型集合
     * @return 附件信息
     */
    @Override
    public Map<String, List<SysFileInfoEntity>> getFileMapByBizIdAndType(Integer bizId, List<String> fileCategoryTypeList, Integer status) {
        return fileDomainDao.getFileMapByBizIdAndType(bizId, fileCategoryTypeList, status);
    }

    @Override
    public SysFileBusinessEntity saveFileBusiness(SysFileBusinessEntity sysFileBusinessEntity) {
        return fileDomainDao.saveFileBusiness(sysFileBusinessEntity);
    }

    @Override
    public Integer queryFileCount(SysFileBusinessEntity sysFileBusinessEntity) {
        return fileDomainDao.queryFileCount(sysFileBusinessEntity);
    }

    @Override
    public void updateFileBusiness(SysFileBusinessEntity sysFileBusinessEntity) {
        fileDomainDao.updateFileBusiness(sysFileBusinessEntity);
    }

    @Override
    public List<SysFileBusinessEntity> queryFileBusinessList(SysFileBusinessEntity sysFileBusinessEntity) {
        return fileDomainDao.queryFileBusinessList(sysFileBusinessEntity);
    }

    @Override
    public IPage<SysFileBusinessEntity> queryContractFile(Page page, SysFileBusinessEntity sysFileBusinessEntity) {
        return fileDomainDao.queryContractFile(page, sysFileBusinessEntity);
    }

    @Override
    public void saveFileBusiness(String bizModule, Integer bizId, String bizCategory, List<FileDTO> fileList) {
        fileDomainDao.saveFileBusiness(bizModule, bizId, bizCategory, fileList);
    }

    @Override
    public List<SysFileInfoEntity> queryFileInfo(String bizModule, Integer bizId, String bizCategory) {
        return fileDomainDao.queryFileInfo(bizModule, bizId, bizCategory);
    }
}
